﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace UI
{
    public partial class FmUchange : Form
    {
        public string UserID;
        public string status;
        public UserMessage  myParentErm;
        public FmUchange()
        {
            InitializeComponent();
        }
        BLL.Users bLKM = new BLL.Users ();
        Model.Users  mLKM = new Model.Users ();
        private void FmUchange_Load(object sender, EventArgs e)
        {
            btnSubmit.Text = status;
            if (status == "修改")
            {
                DataTable dt = bLKM.select("UserID='" + UserID  + "'");
                textBox1.Text = dt.Rows[0]["UserID"].ToString();
                textBox2.Text = dt.Rows[0]["Name"].ToString();
                textBox3.Text = dt.Rows[0]["Number"].ToString();
            }

        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            mLKM.UserID = textBox1.Text;
            mLKM.Name = textBox2.Text;
            mLKM.Number = textBox3.Text;
            bool result = false;
            switch (status)
            {
                case "修改":
                    mLKM.UserID = UserID;
                    result = bLKM.update(mLKM, UserID);
                    break;
                case "添加":
                    result = bLKM.insert(mLKM);
                    break;
            }
            if (result)
            {
                myParentErm.bindGrudView();
                MessageBox.Show(status + "成功！");
            }
            else
                MessageBox.Show(status + "失败！");

        }
    }
}
